home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: realloc(NULL,100)
- Date: 28 Feb 1996 22:18:25 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Feb28151825@qcd.lanl.gov>
- References: <31346CB0.41C67EA6@jupiter.di.uminho.pt>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: Rui Bastos's message of Wed, 28 Feb 1996 14:54:40 +0000
-
- In article <31346CB0.41C67EA6@jupiter.di.uminho.pt>
- Rui Bastos <rui@jupiter.di.uminho.pt> writes:
-
- RB: Hi,
- RB:
- RB: Does anybody knows what's the expected behaviour of this program?
-
- There is no expected behaviour from a program that invokes undefined
- behaviour.
-
- RB:
- RB: #include <stdio.h>
- RB: #include <malloc.h>
-
- There is no such header in standard C. realloc is declared in
- <stdlib.h>. If you include <malloc.h>, the behaviour is undefined.
-
- RB:
- RB: main()
- RB: {
- RB: void *x=NULL;
- RB: x=realloc(NULL,100);
-
- If you had included <stdlib.h> instead, then this call is equivalent
- to calling malloc(100).
-
- RB: printf("%p\n",x);
- RB: }
- RB:
- RB: I tested it under diferent compilers/operating systems
- RB: and it returns null, others returns a valid address and other
- RB: crashes.
-
- Except for the undefined behaviour, returning null or a valid address
- are both correct behaviours. Crashing is not.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-